//
//  PhoneAlertView.m
//  fitnessmanage
//
//  Created by wujian on 2017/12/12.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "PhoneAlertView.h"

@implementation PhoneAlertView

-(id)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        UIView *alphaView = [[UIView alloc] init];
        alphaView.backgroundColor = [CSBlackColor colorWithAlphaComponent:0.6];
        [self addSubview:alphaView];
        self.alphaView = alphaView;
        
        UIView *whiteView = [[UIView alloc] init];
        whiteView.backgroundColor = CSWhiteColor;
        [self addSubview:whiteView];
        self.whiteView = whiteView;
        
        UIImageView *phoneImageView = [[UIImageView alloc] init];
        phoneImageView.image = [UIImage imageNamed:@"icon_callnum"];
        [self addSubview:phoneImageView];
        self.phoneImageView = phoneImageView;
        
        UILabel *phoneLabel = [[UILabel alloc] init];
        phoneLabel.text = @"13122348898";
        phoneLabel.font = [UIFont systemFontOfSize:27.0];
        phoneLabel.textColor = CSColorFromRGB(0x0a0a0a);
        [self addSubview:phoneLabel];
        self.phoneLabel = phoneLabel;
        
        __weak typeof(self) weakSelf = self;
        
        MOFSBottomView *bottomView = [[MOFSBottomView alloc] init];
        
        bottomView.commitBlock = ^{

            [weakSelf removeFromSuperview];
            
            NSMutableString* str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",weakSelf.phone];
            
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
            
        };
        
        bottomView.cancelBlock = ^{
            
            [weakSelf removeFromSuperview];
        };
        
        [self addSubview:bottomView];
        self.bottomView = bottomView;
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    

    [self.alphaView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.edges.mas_equalTo(self);
    }];
    
    [self.whiteView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.center.mas_equalTo(self);
        
        make.left.mas_equalTo(self).offset(20);
        
        make.right.mas_equalTo(self).offset(-20);
    }];
    
    [self.phoneImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.whiteView).offset(20);
        
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    [self.phoneLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(self.phoneImageView.mas_bottom).offset(20);
        
        make.centerX.mas_equalTo(self.whiteView);
    }];
    
    [self.bottomView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.top.mas_equalTo(self.phoneLabel.mas_bottom).offset(30);
        
        make.left.width.bottom.mas_equalTo(self.whiteView);
    }];
}

@end
